package it.polimi.travelDream.web.beans;


import it.polimi.it.TravelDream.ejb.UserMgr;
import it.polimi.it.TravelDream.ejb.eaos.HotelDTO;
import it.polimi.it.TravelDream.ejb.eaos.SearchDTO;
import it.polimi.it.TravelDream.entities.BasicProdMgr;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;


@ManagedBean
@RequestScoped
public class searchHotelBean {
	
	@EJB
	private BasicProdMgr basicProdMgr;
	
	@EJB
	private UserMgr userMgr;
	
	private SearchDTO search;
	
	private List<HotelDTO> hotelsList; 
	
	private List<HotelDTO> hotelsFiltered;
	
	private HotelDTO selectedHotel;
	


	public List<HotelDTO> getHotelsList() {
		return hotelsList;
	}
	public void setHotelsList(List<HotelDTO> hotelsList) {
		this.hotelsList = hotelsList;
	}
	
	public List<HotelDTO> getHotelsFiltered() {
		return hotelsFiltered;
	}
	public void setHotelsFiltered(List<HotelDTO> hotelsFiltered) {
		this.hotelsFiltered = hotelsFiltered;
	
	}
	
   public HotelDTO getSelectedHotel() {
		return selectedHotel;
	}
	public void setSelectedHotel(HotelDTO selectedHotel) {
		this.selectedHotel = selectedHotel;
	}
public searchHotelBean() {
		search = new SearchDTO();
	}
	public SearchDTO getSearch() {
		return search;
	}

	public void setSearch(SearchDTO search) {
		this.search = search;
	}
	
	@PostConstruct
	public void getAllHotels() {
	hotelsList = new ArrayList<HotelDTO>();
	hotelsList=basicProdMgr.getHotelsList(search.getKeySearch());
	//System.out.println("***********************");
	
	}
	
	public void purchaseHotel(){
		selectedHotel.setIdbuyer(userMgr.getUserDTO().getEmail());
		basicProdMgr.purchase(selectedHotel);
		
		
	}
	
	
	

	
	}
	
	


